from race.Player import *
import logging.config
from threadJob import *
from pynput.mouse import Controller as mController
from pynput.keyboard import Controller as kController
from pynput.keyboard import Key
import functools

logging.config.fileConfig('./util/logging.conf')
log = logging.getLogger("example")

"""
    子类描述：
        1、武僧坦克类
"""


class PaladinTank(Player):

    def on_keyboard_press_son_before_thread(self, key):
        log.debug("on_keyboard_press_son_before_thread 1:进入了函数")
        # 有些按键是直接终止别人的，继续自己的，有些不是这样的，因此要区别对待【排列组合，情况非常多】/【也要超级符合每个职业的操作习惯】
        if key in (
                Key.f1, Key.f2, Key.f3, Key.f4, Key.f5, Key.f6, Key.f7, Key.f8, Key.f9, Key.f10, Key.f11,
                Key.f12):
            pass
        elif key == Key.enter:
            pass
        elif key == Key.space:
            pass
        elif key == Key.alt_l:
            pass
        elif key == Key.ctrl_l:
            pass
        elif key == Key.caps_lock:
            pass
        elif key == Key.shift_l:
            pass
        elif key.char == 'a':
            # 不终止别人，后面让只允许一个线程执行的逻辑来顺序排
            # ★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|
            # 并行并发执行的折中方案【通过触发其他按键，这样的好处是线程池统一管理了】
            pass
        elif key.char == 'z':
            pass
        elif key.char == 'q':
            pass
        elif key.char == 'w':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'r':
            # 终止掉别人
            # interruptAllByForce()
            pass
        elif key.char == 'g':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'x':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'v':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'h':
            # 终止掉别人
            # self.interruptAllByForce()
            pass
        elif key.char == 'c':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'e':
            pass
        elif key.char == 's':
            pass
        elif key.char == 'd':
            pass
        elif key.char == 'f':
            pass
        elif key.char == 'b':
            pass
        return

    # 执行父类的方法
    # @logAop
    def a(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        self.kb.press('`')  # 触发-->parallel1
        self.kb.release('`')
        #
        # self.kb.press(Key.alt_l)
        # self.kb.release(Key.alt_l)

        # super().a()
        self.click(self.kb, '1', 3)
        loopCount = 0
        while True:
            # 技能激活，在边框变成金色（红/绿都可以明显识别），5*5的一个小方块，来判断平均像素值。低于或者高于某个像素值，就触发连续按某个按键。
            # self.pubAvgColorTiggerKeyBloodBarMode(704, 1040, 5, 5, 140, 'r', 'big', '0', 0.7, 7)
            self.click(self.kb, '1', 3)
            self.click(self.kb, '3', 3)
            self.click(self.kb, '4', 3)
            self.click(self.kb, '5', 3)


    def parallel1(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        while self.ui.stopLoop == False:

            # 闪耀之光
            self.pubAvgColorTiggerKeyBuffMode(self.WA_SQUARE_ZFX_X1, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
                                              self.WABloodBarDeltaY,
                                              self.WA_SQUARE_ZFX_AvgColor,
                                              'r', 'big', '0', 0.06, 3, '1')

            # 3***判断
            avgColorNumber = self.pubAvgColorNoTrigger(self.WA_STAR_X3, self.WA_STAR_Y, self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, 'r', 0.06)
            if avgColorNumber > self.WABloodBarAvgColor:
                # 以血条为边界
                avgColor1 = self.pubAvgColorNoTrigger(727, 1032, 3, 3, 'r', 0)
                if avgColor1 < self.WABloodBarAvgColor:
                    self.click(self.kb, '0', 3)
                else:
                    self.click(self.kb, '2', 3)
            else:
                self.click(self.kb, '1', 3)
        return

    def parallelAlt2(self):
        # # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        # while self.ui.stopLoop == False:
        #     self.click(self.kb, '7', 2)
        #     self.click(self.kb, '6', 3)
        #     self.click(self.kb, '9', 2)
        #     self.click(self.kb, '3', 2)
        #     self.click(self.kb, '4', 2)
        #     self.click(self.kb, '5', 2)
        return

    def on_mouse_click_son_before_thread(self, x, y, button, pressed):
        # 在鼠标点击，终止和打断其他动作（有些职业需要，有些不需要）??????????
        pass
        return

    def mouseRightClick(self, x, y):
        log.debug('★圣骑士坦克，鼠标click-right，需要开始执行的内容★')
        return

    def x(self):
        for i in range(1, 4):
            self.click(self.kb, 't', 2)
            sleep(0.1)

        # 打断后的继续
        self.click(self.kb, 'a', 1)
        return


class HealPaladin(Player):

    def mouseUp(self, x, y):
        # AOE 抬团血
        sleep(1.1)
        # 美德道标必须出来
        self.click(self.kb, '4', 2)

        while True:
            self.pubAvgColorCDNumberDeductInBlock(814, 944, 15, 15, 'g', 0, '4', 'b', 100)
            self.click(self.kb, '4', 1)
            self.pubAvgColorCDNumberDeductInBlock(782, 944, 15, 15, 'g', 0, '5', 'b', 100)
            # 不能固定(节约时间)
            self.click(self.kb, '4', 1)
            self.pubAvgColorCDNumberDeductInBlock(814, 944, 15, 15, 'g', 0, '4', 'b', 100)
            self.click(self.kb, '4', 2)
            self.click(self.kb, '7', 2)
            sleep(0.01)

    def mouseDown(self, x, y):
        # 单体抬血
        while True:
            avgColor1 = self.pubAvgColorNoTrigger(914, 944, 15, 15, 'r', 0)
            while avgColor1 > 200:
                self.click(self.kb, '1', 8)
                sleep(0.01)
                avgColor1 = self.pubAvgColorNoTrigger(914, 944, 15, 15, 'r', 0)
            self.click(self.kb, '2', 5)
            sleep(0.01)
            # 补豆子
            self.click(self.kb, '8', 2)
            # 炙天使
            self.click(self.kb, '9', 2)
            # 神圣能量的五颗星的判断
            avgColor2 = self.pubAvgColorNoTrigger(812, 419, 6, 6, 'r', 0)
            if avgColor2 > 200:
                self.click(self.kb, '6', 8)
            else:
                self.click(self.kb, '1', 3)
                # 3 or 7
                strTempDate = int(datetime.datetime.now().strftime('%S'))
                if strTempDate % 2 == 0:
                    self.click(self.kb, '3', 2)
                else:
                    self.click(self.kb, '7', 2)
            # 补豆子
            self.click(self.kb, '8', 2)

    def on_mouse_scroll_son_before_thread(self, dx, dy):
        if dy < 0:
            # 滚轮向下
            self.interruptAllByForceMouseUpDown()  # 强制打断正在运行的循环
        elif dy > 0:
            # 滚轮向上
            self.interruptAllByForceMouseUpDown()  # 强制打断正在运行的循环
        return

    def space(self):
        # self.click(self.kb, Key.tab, 1)
        self.click(self.kb, '8', 6)
        return

    def a(self):
        # self.click(self.kb, Key.tab, 1)
        self.click(self.kb, '8', 6)
        return

    def s(self):
        # 赚豆子
        self.click(self.kb, '8', 6)
        return

    # def f(self):
    #     #self.click(self.kb, Key.tab, 1)
    #     self.click(self.kb, '8', 6)
    #     return

    def q(self):
        for i in range(1, 4):
            self.click(self.kb, '4', 6)
        return

    def mouseRightClick(self, x, y):
        log.debug('★治疗SM鼠标click-right，需要开始执行的内容★')
        return

    def parallel1(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        for i in range(1, 888888):
            sleep(0.2)
            self.click(self.kb, 'i', 3)
            sleep(0.2)
            self.click(self.kb, 'k', 3)
        return

    def parallelAlt2(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        for i in range(1, 888888):
            # sleep(0.01)
            # self.click(self.kb, 't', 3)
            # sleep(0.01)
            sleep(1)
            pass


if __name__ == '__main__':
    pass
